﻿using EFModel;
using IServices;
using Microsoft.EntityFrameworkCore;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using xm.Controllers;

namespace Serives
{
    [Obsolete]
    public class Teconfig_major: Iconfig_major
    {
        private readonly MyDBContext he;

        public Teconfig_major(MyDBContext he)
        {
            this.he = he;
        }

        Task<ResultInfo> Iconfig_major.Index8(int currentPage, int pageSize)
        {
            return Task.Run(() => {
                var con = he.config_major;
                var list = he.config_major
                    .Select(e => new { e.major_id, e.major_kind_id, e.major_kind_name, e.major_name, e.mak_id, e.test_amount, e.config_major_kind })
                    .OrderBy(q => q.mak_id).Skip((currentPage - 1) * pageSize).Take(pageSize)
                    .ToList();
                int cont = con.Count();
                ResultInfo result = new ResultInfo()
                {
                    Data = list,
                    Message = "查询数据成功",
                    Status = 200,
                    Row = cont
                };
                return result;
            });
        }

        Task<int> Iconfig_major.Inser5(string major_kind_id, string major_kind_name, string major_id, string major_name, string test_amount)
        {
            return Task.Run(() => {
                string sql = $@"insert into [dbo].[config_major]([major_kind_id], [major_kind_name], [major_id], [major_name], [test_amount])
                            values('{major_kind_id}','{major_kind_name}','{major_id}','{major_name}',0);";

                int i = he.Database.ExecuteSqlCommand(sql);
                return i;
            });
        }

        Task<int> Iconfig_major.delt5(int mak_id)
        {
            return Task.Run(() => {
                string sql = $@"delete from [dbo].[config_major]
                            where [mak_id]={mak_id}";

                int i = he.Database.ExecuteSqlCommand(sql);
                return i;
            });
        }

        Task<string> Iconfig_major.Zc()
        {
            return Task.Run(() => {
                var list = he.config_major_kind;
                return JsonConvert.SerializeObject(list);
            });
        }
    }
}
